package com.iweb;

import java.util.TreeSet;

//不允许用if else 写代码
//给定一个Student类 name  age  chinese  math english
//输出规则 按照成绩的总分 倒序输出 如果总分相同 按照语文成绩的倒序
//如果语文成绩也相同 按照数学成绩 倒序输出
//如果数学成绩也想通 按照年龄的顺序 输出
//如果 年龄相同 按照姓名的长度 顺序输出
public class Demo5 {
    public static void main(String[] args) {
        TreeSet<Student> students = new TreeSet<>();
        students.add(new Student("小1",20,100,90,60));
        students.add(new Student("小2",20,60,70,60));
        students.add(new Student("小3",20,80,50,60));
        students.add(new Student("小4",20,20,50,60));
        students.add(new Student("小5",20,15,50,60));

        for (Student s:students){
            System.out.println(s);
        }
    }
}

class Student implements Comparable<Student>{
    private String name;
    private int age;
    private int chinese;
    private int math;
    private int english;
    @Override
    public int compareTo(Student o) {
        int num= (o.getChinese()+o.getMath()+o.getEnglish())-(this.chinese+this.math+this.english);
        num=num==0?o.getChinese()-this.chinese:num;
        num=num==0?o.getMath()-this.math:num;
        num=num==0?this.age-o.getAge():num;
        num=num==0?this.name.length()-o.getName().length():num;
        return num;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public Student(String name, int age, int chinese, int math, int english) {
        this.name = name;
        this.age = age;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }


}
